package com.zzb.projectfactory.framework.common;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 基本返回
 * Created by zhangzhenbin on 2016/10/10.
 */
public class BaseResponse<T> implements Serializable {
    public final static int SUCCESS = 1;
    public final static int FAIL = 0;

    private static final long serialVersionUID = 1596948553456839650L;
    private int status;
    private String msg;
    private T content;

    public BaseResponse() {
        super();
    }

    public BaseResponse(int status, String msg) {
        super();
        this.status = status;
        this.msg = msg;
    }

    public BaseResponse(int status, String msg, T content) {
        super();
        this.status = status;
        this.msg = msg;
        this.content = content;
    }

    public boolean isSuccess() {
        return this.status == SUCCESS;
    }

    public T getContent() {
        return content;
    }

    public void setContent(T content) {
        this.content = content;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Map<String, Object> toMap() {
        Map<String, Object> map = new HashMap<>();
        map.put("status", this.getStatus());
        map.put("msg", this.getMsg());
        map.put("content", this.getContent());
        return map;
    }

    @Override
    public String toString() {
        return "BaseResponse{" +
                "status=" + status +
                ", msg='" + msg + '\'' +
                ", content=" + content +
                '}';
    }

}
